
#include "main.h"


void e2_Write( unsigned int Address, unsigned char Ch ) 
{
	unsigned int i = 700;
	EEPROM_WRITE(Address, Ch);
	while(--i);
}	
 
unsigned char e2_Read( unsigned int Address )
{
	return ( EEPROM_READ(Address) );
}
 
void E2_Delete( unsigned int Address, unsigned int ByteCount )
{
	unsigned int i;
	for ( i = 0;  i < ByteCount; i++ )
	{
		e2_Write( (Address + i), 0xFF );
	}
}
  
void E2_SaveTo( unsigned int Address, unsigned char *Buffer, unsigned char ByteCount )
{
	unsigned char i;
	for ( i = 0;  i < ByteCount; i++ )
	{
		e2_Write( (Address + i), Buffer[i]);
	}
}

void E2_LoadFrom( unsigned char *Buffer, unsigned int Address, unsigned char ByteCount )
{
	unsigned char i;
	for ( i = 0;  i < ByteCount; i++ )
	{
		Buffer[i] = e2_Read( Address + i );
	}
	//Buffer[i] = 0;					  /* end of string */
}

void E2_Str_SaveTo( unsigned int Address, register const unsigned char *Str )
{
	do
	{
		e2_Write( (Address++), *Str);
	}
	while ( *Str++ );
}

unsigned char E2_Str_LoadFrom( unsigned char *Str, unsigned int Address )
{
	unsigned char i = 0;

	while ( TRUE )
	{
		Str[i] = e2_Read( Address++ );
		if ( Str[i] == 0xFF || Str[i] == 0 )
		{	
			Str[i] = 0;		
			break;
		}
		i++;
	}
	//while( Str[i++] );
	
	return i;
}

void E2_PrintStr(unsigned int Address, unsigned char X, unsigned char Y, unsigned char ClearDisplay)
{
	unsigned char str[21];
	E2_Str_LoadFrom(str, Address);
//	lcd_print_str(str,X,Y,ClearDisplay);
}

//	while( !(Result = (unsigned char)*s1 - (unsigned char)*s2++) && *s1++ )
//		errno++;

//	return Result;

int E2_StrCmp( register const unsigned char* Reference, unsigned int Address  )
{
	register signed int Result;
	
	errno = 0;
	
	while( !(Result = (unsigned char)*Reference - e2_Read(Address++) ) && *Reference++ )
		errno++;

	return Result;
}
 
/* unsigned char* e2_StrLoad ( unsigned char* Str, unsigned int Address ) */
/* { */
/* 	while ( *Str++ = e2_Read(Address++) ) */
/* 		continue; */
	
/* 	return Str; */
/* } */
 
/* unsigned char e2_Str_Load_Number( unsigned char* Str, unsigned int Address ) */
/* { */
/* 	unsigned int i = 0; */

/* /\* 	do *\/ */
/* /\* 	{ *\/ */
/* /\* 		if ( i > 1024 ) *\/ */
/* /\* 		{ *\/ */
/* /\* 			i = 0; *\/ */
/* /\* 			break; *\/ */
/* /\* 		} *\/ */

/* /\* 		Str[i] = e2_Read( Address++ ); *\/ */

/* /\* 		if ( Str[i] < '0' || Str[i] > '9'  ) *\/ */
/* /\* 		{ *\/ */
/* /\* 			Str[i] = 0;		 *\/ */
/* /\* 			break; *\/ */
/* /\* 		} *\/ */
/* /\* 	} *\/ */
/* /\* 	while( Str[i++] ); *\/ */
	
/* 	return i; */
/* } */
